package com.example.mytestdemo.viewpage2

import android.content.Context
import android.util.AttributeSet
import android.util.Log
import android.view.LayoutInflater
import android.widget.FrameLayout
import androidx.databinding.DataBindingUtil
import com.example.mytestdemo.R
import com.example.mytestdemo.databinding.CustomFramelayoutBinding
import com.example.mytestdemo.viewpage2.adapter.ImyAdapterListener
import com.example.mytestdemo.viewpage2.adapter.MyViewPager2RecycleAdapter

/**
 * @author tgw
 * @date 2022/7/6
 */
class TestCustomFrameLayout @JvmOverloads constructor(
    context: Context, attrs: AttributeSet? = null
) : FrameLayout(context, attrs) {

    companion object {
        private const val TAG = "TestCustomFrameLayout"
    }


    private val mBind: CustomFramelayoutBinding = DataBindingUtil.inflate(
        LayoutInflater.from(context),
        R.layout.custom_framelayout,
        this, true
    )

    fun initCustomFrameLayout(){
        val data = arrayListOf<String>()
        (0..10).forEach {
            data.add("TestCustomFrameLayout数据$it")
        }

        val myAdapter = MyViewPager2RecycleAdapter(object : ImyAdapterListener {
            override fun listener(position: Int) {
                Log.d(TAG, "tgw listener: $position")
            }

        })//嵌套recyclerview
        myAdapter.setList(data)



        mBind.viewpager2.adapter = myAdapter
        mBind.viewpager2.setCurrentItem(2)
        myAdapter.notifyItemChanged(2)


    }

}